!
! "LJA USB MODEM"
!	
@ORIGINATE
@ANSWER
!
! ---- Initial DCE setup ----
!
ifstr 5 1 "0"
serreset 230400, 0, 8, 1
jump 2
!
@LABEL 1
serreset 230400, 0, 8, 1
@LABEL 2
hsreset 0 0 0 0 0 0
settries 0
!
! ʃR[h`ԁF("ATV1")
!
matchclr
matchstr 1 3 "OK\13\10"
write "ATV1\13"
matchread 40
!
@LABEL 3
!
! Get the DCE's attention("AT")
!
matchclr
matchstr 1 4 "OK\13\10"
write "AT\13"
matchread 40
!
@LABEL 4
!
! Setup the DCE("ATZ")
!
!matchclr
!matchstr 1 5 "OK\13\10"
!write "ATZ\13"
!matchread 60
!
@LABEL 5
!
! Setup the DCE("AT&D2&C1")
!
matchclr
matchstr 1 6 "OK\13\10"
write "AT&D2&C1\13"
matchread 60
inctries
iftries 3 101
!
! Reset the DCE on setup failure
!
DTRClear
pause 5
DTRSet
flush
jump 4
!
@LABEL 6
ifANSWER 32
@LABEL 19
! Display the full dialstring contained in Varstring 1
note "^1 Ƀ_CĂ܂..." 3
!
! Varstrings 7, 8 and 9, contain dialstring fragments
!    Long phone numbers may need to be split into smaller groups
!    for the DCE to use
!
! Varstring 3:  "p" for pulse & "t" for tone dialing
! Varstring 8 == blank (dialstring in varstring 7)
! Varstring 9 == blank (dialstring in varstrings 7 & 8)
! Otherwise (dialstring in varstrings 7, 8 & 9)
! \^ is added to the dialstring to force the DCE to generate a data tone
ifstr 8 27 " "
ifstr 9 24 " "
!
!  Write dialstring in varstrings 7, 8 & 9
!
matchclr
matchstr 1 21 "OK\13\10"
write "ATDT^7;\13"
matchread 400
jump 101
!
@LABEL 21
matchclr
matchstr 1 22 "OK\13\10"
write "ATDT^8;\13"
matchread 400
jump 101
!
@LABEL 22
write "ATDT^9\13"
jump 32
!
@LABEL 24
!  Write dialstring in varstrings 7 & 8
matchclr
matchstr 1 25 "OK\13\10"
write "ATDT^7;\13"
matchread 400
jump 101
!
@LABEL 25
write "ATDT^8\13"
jump 32
!
@LABEL 27
!  Write dialstring in varstring 7
write "ATDT^7\13"
!
!    ---- Connection responce ----
!
! The following section will parse DCE responces of two types:
!   X0 CONNECT
!      RING
!   X1 CONNECT ***K/V.110
!      RING xxx-xxxx ***K/V.110
!
@LABEL 32
matchclr
matchstr  1 81  "RING"
matchstr  2 102 "NO DIALTONE\13\10"
matchstr  3 103 "NO CARRIER"
matchstr  4 103 "ERROR\13\10"
matchstr  5 104 "BUSY\13\10"
matchstr  6 105 "NO ANSWER\13\10"
matchstr  7 33  "CONNECT "
matchstr  8 59  "CONNECT\13\10"
matchstr  9 103 "DELAYED\13\10"
matchread 700
ifANSWER 32
jump 101
!
!  Parse the speed of connect result cord
!
@LABEL 33
matchclr
matchstr  1 41 "1200"
matchstr  2 42 "2400"
matchstr  3 43 "4800"
matchstr  4 44 "7200"
matchstr  5 45 "9600"
matchstr  6 46 "12000"
matchstr  7 47 "14400"
matchstr  8 48 "19200"
matchstr  9 49 "38400"
matchstr  10 50 "57600"
matchstr  11 51 "115200"
matchstr  12 52 "230400"
matchread 30
jump 59
!
! -- Connection rates --
! CommunicatingAt informs ARA of the raw DCE to DCE
! connection speed.
!
@LABEL 41
note "1200bps Őڑ܂." 2
CommunicatingAt 1200
jump 60
!
@LABEL 42
note "2400bps Őڑ܂." 2
CommunicatingAt 2400
jump 60
!
@LABEL 43
note "4800bps Őڑ܂." 2
CommunicatingAt 4800
jump 60
!
@LABEL 44
note "7200bps Őڑ܂." 2
CommunicatingAt 7200
jump 60
!
@LABEL 45
note "9600bps Őڑ܂." 2
CommunicatingAt 9600
jump 60
!
@LABEL 46
note "12000bps Őڑ܂." 2
CommunicatingAt 12000
jump 60
!
@LABEL 47
note "14400bps Őڑ܂." 2
CommunicatingAt 14400
jump 60
!
@LABEL 48
note "19200bps Őڑ܂." 2
CommunicatingAt 19200
jump 60
!
@LABEL 49
note "38400bps Őڑ܂." 2
CommunicatingAt 38400
jump 60
!
@LABEL 50
note "57600bps Őڑ܂." 2
CommunicatingAt 57600
jump 60
!
@LABEL 51
note "115200bps Őڑ܂." 2
CommunicatingAt 115200
jump 60
!
@LABEL 52
note "230400bps Őڑ܂." 2
CommunicatingAt 230400
jump 60
!
@LABEL 59
note "ڑ܂." 2
jump 60
!
! Look for reliablilty and compression results 
! at the end of the connect result.
!
@LABEL 60
jump 70
matchclr
matchstr 1 61  "/PACKET\13\10"
matchstr 2 62  "/PPP\13\10"
matchstr 3 63  "/MP\13\10"
matchstr 4 64  "/V.110\13\10"
matchstr 5 65  "/PIAFS\13\10"
matchstr 6 66  "/V.120\13\10"
matchread 30
jump 70
!
! -- DCE error correction link negotiation --
! Userhook 2 informs ARA that a DCE-to-DCE error
! correcting protocol has been negotiated
!
@LABEL 61
note "pPbg[hŐڑ܂." 2
jump 70
!
@LABEL 62
note "64000bps/PPP Őڑ܂." 2
jump 70
!
@LABEL 63
note "128000bps/MP Őڑ܂." 2
jump 70
!
@LABEL 64
note "38400bps/V.110 Őڑ܂." 2
jump 70
!
@LABEL 65
note "32000bps/PIAFS Őڑ܂." 2
jump 70
!
@LABEL 66
note "38400bps/V.120 Őڑ܂." 2
jump 70
!
! -- Normal exit after "CONNECT" --
!
!  This TA has been setup to do CTS handshaking,
!  and we assume that a CTS handshaking cable is being used.
!
@LABEL 70
! Turn on CTS handshaking.
HSReset 0 1 0 0 0 0
!
ifANSWER 71
pause 30
@LABEL 71
exit 0
!
! ---- Answer calls ----
!
!	A RING result from the DCE and in ANSWERING mode
!	claims the serial port and answering the phone
!
@LABEL 81
ifORIGINATE 32
userhook 1
note "ĂdbɉĂ܂..." 2
write "ATA\13"
jump 32
!
! ---- Hang up and reset DCE ----
!
@HANGUP
@LABEL 90
settries 0
HSReset 0 0 0 0 0 0
!
@LABEL 92
!  Escape from data to command DCEatchclr
pause 15
matchstr 1 96 "OK\13\10"
write "+++"
matchread 30
!
@LABEL 94
! Force a hangup
matchclr
matchstr 1 98 "NO CARRIER\13\10"
matchstr 2 99 "OK\13\10"
matchstr 3 98 "ERROR\13\10"
matchstr 4 98 "0\13\10"
write "ATH\13"
matchread 30
! 
! Try to get control of the DCE by toggling DTR
DTRClear
pause 5
DTRSet
flush
!
! Try the hangup sequence three times otherwise declare and error
inctries
iftries 3 101
jump 92
!
@LABEL 96
! Pause between data and command mode
pause 10
jump 94
!
@LABEL 98
! Recall the factory settings
pause 15
matchclr
matchstr 1 99 "OK\13\10"
write "AT\13"
matchread 30
jump 101
!
@LABEL 99
exit 0
!
! ---- Error messages -----
!
! DCE Not Responding
!
@LABEL 101
exit -6019
!
! No Dial Tone
@LABEL 102
exit -6020
!
! No Carrier or Error
@LABEL 103
exit -6021
!
! Busy
@LABEL 104
exit -6022
!
! No Answer
@LABEL 105
exit -6023
!
! User Cancellation
@LABEL 107
exit -6002 "User cancelled the connection attempt."